﻿package core.ui.demo;

import javafx.collections.ObservableList;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
/**
 * @author 李瑜
 * @since JavaFX 8.0
 */
public class DemoTableView
{
	@SuppressWarnings("unchecked")
	public static TableView<Person> getTableView()
	{
		TableView<Person> tableView = new TableView<>();
		TableColumn<Person, String> column1 = new TableColumn<>("姓名");
		column1.setCellValueFactory(new PropertyValueFactory<Person,String>("Name"));
		TableColumn<Person, String> column2 = new TableColumn<>("电话");
		TableColumn<Person, String> column3 = new TableColumn<>("家乡");
		column3.setCellValueFactory(new PropertyValueFactory<Person,String>("Home"));
		TableColumn<Person, String> column4 = new TableColumn<>("移动");
		column4.setCellValueFactory(new PropertyValueFactory<Person,String>("CMCC"));
		TableColumn<Person, String> column5 = new TableColumn<>("联通");
		column5.setCellValueFactory(new PropertyValueFactory<Person,String>("CMUT"));
		column2.getColumns().addAll(column4,column5);
		ObservableList<Person> list = tableView.getItems();
		list.addAll(new Person[]
				{
					new Person("李  瑜", "10010", "", "河南新乡"),
					new Person("吕  中", "10086", "", "河南信阳"),
					new Person("李志刚", "", "11155", "河南洛阳"),
					new Person("户庆凯", "", "120", "河南安阳"),
					new Person("胡烈豪", "", "130", "河南周口"),
					new Person("杨永浩", "", "140", "河南商丘"),
				});
		tableView.getColumns().addAll(column1,column2,column3);
		return tableView;
	}
}
